package com.imooc.demo.pattern.proxy;

import com.imooc.demo.pattern.proxy.jdk.dynamic.AplipayInvocationHandler;
import com.imooc.demo.pattern.proxy.jdk.dynamic.JdkDynamicProxyUtil;
import com.imooc.demo.pattern.proxy.jdk.statics.impl.ToCPayment;
import com.imooc.demo.pattern.proxy.jdk.statics.impl.ToCPaymentImpl;

import java.lang.reflect.InvocationHandler;

public class ProxyDemo {
    public static void main(String[] args) {
        // 静态代理
//        AlipayToC alipayToC = new AlipayToC(new ToCPaymentImpl());
//        alipayToC.pay();

        // 动态代理
        ToCPayment toCPayment = new ToCPaymentImpl();
        InvocationHandler handler = new AplipayInvocationHandler(toCPayment);
        ToCPayment toCProxy = JdkDynamicProxyUtil.newProxyInstance(toCPayment, handler);
        toCProxy.pay();
    }
}
